package cn.nwpu.eckel.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.nwpu.eckel.Dao.ForecastDao;
import cn.nwpu.eckel.Dao.OrderDao;
import cn.nwpu.eckel.Dao.ScheduleReceiptDao;
import cn.nwpu.eckel.model.Source;

/**
 * Servlet implementation class DeleteSource
 */
@WebServlet("/DeleteSource")
public class DeleteSource extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteSource() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		int id=Integer.parseInt(request.getParameter("id"));
		int mpsNo=Integer.parseInt(request.getParameter("mpsNo"));
		String source=request.getParameter("source");
		Source s;
		if(source.equals("order")){
			s=OrderDao.deleteOrder(id);
		}else if(source.equals("forecast")){
			s=ForecastDao.deleteForecast(id);
		}else{
			s=ScheduleReceiptDao.deleteScheduleReceipt(id);
		}
		s.afterDelete();
		String rePath="index.jsp?mpsId="+mpsNo+"&source="+source;
		response.sendRedirect(rePath);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
